<template>
  <el-row type="flex" class="setting-flow-container">
    <!--S 合同流程轴 -->
    <div class="setting-flow-axis" id="setting-flow-axis-guide">
      <h3>{{$t('contract.setting.flow.title1')}}</h3>
      <div>
        <el-row
          class="flow-axis-step-box"
          type="flex"
          justify="space-between"
          v-for="key in Object.keys(flowMap)"
          :key="key"
          @click.native="clickFlow(key)">
          <el-row
            class="flow-axis-step"
            :class="[flowMap[key].boxType || 'square', currFlow === key && 'active', (false && flowMap[key].canSwitch) && 'disabled']"
            type="flex" justify="space-between">
            <div>
              <i :class="['iconfont', flowMap[key].icon]"></i>
              {{flowMap[key].name}}
            </div>
            <div v-if="key === 'audit'" class="open-tag">{{$t('common.base.alreadyOpen')}}</div>
          </el-row>
          <div class="open-btn" @click.stop>
            <el-switch v-if="key === 'audit'"/>
          </div>
        </el-row>
      </div>
    </div>
    <!--E 合同流程轴 -->
    <!--S 流程设置 -->
    <div class="setting-flow-main">
      <div class="setting-flow-main-content">
        <flow-setting
          ref="flowSettingRef"
          :type="currFlow"
          :contractTemplateId="contractTemplateId"
          :flow-setting="flowData.flowConfig.flowSetting[currFlow]"
          @saveSubmit="saveSubmit"
          style="height: 100%"/>
      </div>
    </div>
    <!--E 流程设置 -->
  </el-row>
</template>

<script>
import _ from 'lodash';
/** api */
import * as SettingApi from '@src/api/SettingApi.ts';
/** components */
import FlowSetting from './FlowSetting.vue'

import flowMap from '../flowMap';
export default {
  name: 'flow-setting-panel',
  inject: ['flowData'],
  props: {
    // 合同模板id
    contractTemplateId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      currFlow: 'create', // 当前设置的流程
      open: false,

      flowMap,
    }
  },
  methods: {
    clickFlow(type) {
      // if ((!state && this.flowMap[key].canSwitch)) {
      //   return
      // }
      this.currFlow = type;
    },
    saveSubmit(){
      this.submit();
    },
    /** 保存设置 (暴露的方法) */
    submit() {
      return {
        step: '1'
      }
      // try {
      //   let params = this.flowData.flowConfig
                
      //   let res = await SettingApi.saveProcess(params);
      //   if(res.status == 1) {
      //     return this.$platform.notification({
      //       title: res.message,
      //       type: 'error'
      //     });
      //   }

      //   this.$platform.notification({
      //     title: this.$t('common.base.tip.saveSuccess'),
      //     type: 'success'
      //   });
      //   // this.$customerOperateLog(logDataToParams('flow', this.flowData));//记录用户操作日志
      // } catch (error) {
      //   console.error('error', error);
      // }
    }
  },
  mounted() {
  },
  components: {
    [FlowSetting.name]: FlowSetting
  }
}
</script>

<style lang="scss" scoped>
.setting-flow-container{
  width: 100%;
  min-height: calc(100vh - 48px);
  padding: 12px;
  .setting-flow-axis{
    width: 298px;
    min-height: 100%;
    padding: 20px;
    background: #FFFFFF;
    border-radius: 4px;
    .flow-axis-step-box {
      width: 100%;
      .square {
        border-radius: 4px;
      }
      .round {
        border-radius: 4px;
      }
      .open-btn {
        position: absolute;
        top: 40px;
        right: 0;
      }
      &:not(:last-child) {
        .flow-axis-step::after {
          content: "";
          position: absolute;
          left: 50%;
          bottom: -31px;
          display: block;
          transform: translateX(-50%);
          width: 1px;
          height: 30px;
          background: #E6E6E6;
        }
      }
    }
    .flow-axis-step {
      justify-content: flex-start;
      align-items: center;
      cursor: pointer;
      position: relative;
      width: 188px;
      height: 44px;
      margin-top: 30px;
      padding: 12px 10px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #333333;
      background: #FFFFFF;
      border-radius: 4px;
      border: 1px solid #D9D9D9;
      div:nth-child(1){
        @include text-ellipsis();
      }
      i {
        margin-right: 3px;
        font-size: 16px;
        color: $color-primary;
        vertical-align: middle;
      }
      .open-tag {
        width: 52px;
        height: 22px;
        text-align: center;
        color: #67C23A;
        background: #E1F3D8;
        border-radius: 11px;
        border: 1px solid #CFEDC0;
      }
      &.disabled {
        color: #999999;
        background: #F2F2F2;
        border: 1px solid #E6E6E6;
        i {
          color: #999999;
        }
      }
      &.active {
       background: $color-primary-light-1;
        border: 1px solid $color-primary;
      }
    }
  }
    
  .setting-flow-main{
    flex: 1;
    width: 100%;
    min-height: 100%;
    padding-left: 12px;
    &-title{
      width: 100%;
      height: 40px;
      line-height: 40px;
      text-align: center;
      font-style: 14px;
     background: $color-primary-light-1;
    }
    &-content{
      height: 100%;
    }
  }
}

.setting-flow-axis {
  h3 {
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #262626;
    line-height: 20px;
    margin-bottom: 20px;
  }
  .flow-axis-step-box:first-child  {
    .flow-axis-step {
      margin-top: 0px;
    }
  }
}

.setting-flow-main-content {
  padding: 20px 0 16px 20px;
  background: #fff;
  border-radius: 4px;
}
</style>